package test;

/**
 * Created by dell on 2017/5/9.
 */
public class ComplexNumber {
    public int i;
    public double a, b,m;
    static public double W, X, Y;
    static public String Z,z,s;

    public ComplexNumber(){
    }

    public ComplexNumber(double A, double B){
        this.a = A;
        this.b = B;
    }

    public void Show(){
        s = "z = " + a + " + " + b +"i";
        System.out.println("Show a complex number:"+ s );
    }

    public static void Count(ComplexNumber C1,char C2,ComplexNumber C3){
        switch (C2){
            case '+' :
                X = C1.a + C3.a;
                Y = C1.b + C3.b;
                Z = "("+X+")" + "+" + "("+Y+")" + "i";
                break;
            case '-' :
                X = C1.a - C3.a;
                Y = C1.b - C3.b;
                Z = "("+X+")" + "+" + "("+Y+")" + "i";
                break;
            case '*' :
                X = C1.a * C3.a - C1.b * C3.b;
                Y = C1.b * C3.a + C1.a * C3.b;
                Z = "("+X+")" + "+" + "("+Y+")" + "i";
                break;
            case '/' :
                W = Math.pow(C3.a,2)+Math.pow(C3.b,2);
                X = (C1.a * C3.a + C1.b * C3.b)/W;
                Y = (C1.b * C3.a - C1.a * C3.b)/W;
                Z = "("+X+")" + "+" + "("+Y+")" + "i";
                break;
            default:
                System.out.println("The input is not a valid operator!");
        }
    }

    public void Length(){
        if (b != 0){
            double s = (int)Math.pow(a, 2)+Math.pow(b, 2);
            m = Math.sqrt(s);
        }
        else
        if(a>=0)
            m = this.a;
        else
            m = this.a * -1;
        System.out.println("This complex number length is: " + m);
    }

    public static String getCount(){
        return Z;
    }

    public String toString(){
        z = "("+a+")" + "+" + "("+b+")" + "i";
        return z;
    }
}